<?php
// 打开全局的session
session_start();
// 引入数据库连接文件
include("db_conn.php");
// 使用变量分别接收，账号、密码、用户的登录类型
$username=$_POST['username'];
$pass=$_POST['pass'];
$type=$_POST['type'];
// 根据类型查询对应的数据表
if($type=='mana')
    $sql="select * from mana m, soci s where m.ManaNo=s.ManaNo and s.ManaNo='$username' and Pwd='$pass';";
else
    $sql="select * from student where StuNo='$username' and Pwd='$pass';";

// 执行sql语句
$res=mysql_query($sql);
$number=mysql_num_rows($res);
// 判断是否有对应的用户，如果有则登录成功，如果没有则返回首页,继续登录
if($number==0)
    echo "<script>location.href='/szut_myframe/index.php';</script>";
else{
    $row = mysql_fetch_array($res);
    if ($type=="mana"){
        $_SESSION["role"] = $type;
        $_SESSION["username"] = $row["ManaNo"];
        $_SESSION["departno"] = $row["DepartNo"];
        $_SESSION["classno"] = "";
        $_SESSION["SociNo"] = $row["SociNo"];
    }
    else{
        $_SESSION["role"] = $type;
        $_SESSION["username"] = $row["StuNo"];
        $_SESSION["departno"] = "";
        $_SESSION["classno"] = $row["ClassNo"];
    }
    // 登录成功后返回首页，显示对应的功能和登录的用户
    echo "<script>location.href='/szut_myframe/index.php';</script>";
}
?>
